﻿// DlgSetTray.cpp: 实现文件
//

#include "stdafx.h"
#include "Simulate.h"
#include "DlgSetTray.h"
#include "afxdialogex.h"


// DlgSetTray 对话框

IMPLEMENT_DYNAMIC(DlgSetTray, CDialogEx)

DlgSetTray::DlgSetTray(CArray<int>* pTrays, int nTray, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SETTRAY, pParent)
	, m_pTrays(pTrays)
	, m_nTray(nTray)
{

}

DlgSetTray::~DlgSetTray()
{
}

void DlgSetTray::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_listTray);
}


BEGIN_MESSAGE_MAP(DlgSetTray, CDialogEx)
	ON_BN_CLICKED(IDOK, &DlgSetTray::OnBnClickedOk)
END_MESSAGE_MAP()


// DlgSetTray 消息处理程序


BOOL DlgSetTray::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	INT_PTR len = m_pTrays->GetCount();
	CString str;
	int sel = -1;
	for (INT_PTR i = 0; i < len; i++)
	{
		str.Format(L"%i", m_pTrays->GetAt(i));
		m_listTray.AddString(str);
		if (m_pTrays->GetAt(i) == m_nTray)
			sel = i;
	}
	if (sel >= 0)
		m_listTray.SetCurSel(sel);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void DlgSetTray::OnBnClickedOk()
{
	int sel = m_listTray.GetCurSel();
	if (sel < 0)
		EndDialog(IDCANCEL);
	else
	{
		ASSERT(sel < m_pTrays->GetCount());
		m_nTray = m_pTrays->GetAt(sel);
		EndDialog(IDOK);
	}
}
